import tkinter as tk

def add_to_listbox():
    # 获取三个 Entry 的内容
    entry1_text = entry1.get()
    entry2_text = entry2.get()
    entry3_text = entry3.get()
    # 检查是否有内容
    if entry1_text:
        listbox.insert(tk.END, entry1_text)
    if entry2_text:
        listbox.insert(tk.END, entry2_text)
    if entry3_text:
        listbox.insert(tk.END, entry3_text)
    # 清空输入框
    entry1.delete(0, tk.END)
    entry2.delete(0, tk.END)
    entry3.delete(0, tk.END)

def delete_from_listbox():
    # 获取选中项的索引
    selected_index = listbox.curselection()
    if selected_index:
        listbox.delete(selected_index)

def clear_listbox():
    # 清空 Listbox
    listbox.delete(0, tk.END)

# 创建主窗口
root = tk.Tk()
root.title("Entry 和 Listbox 示例")

# 创建三个 Entry 输入框
entry1 = tk.Entry(root)
entry1.pack(pady=5)
entry2 = tk.Entry(root)
entry2.pack(pady=5)
entry3 = tk.Entry(root)
entry3.pack(pady=5)

# 创建三个按钮
add_button = tk.Button(root, text="添加", command=add_to_listbox)
add_button.pack(pady=10)
delete_button = tk.Button(root, text="删除", command=delete_from_listbox)
delete_button.pack(pady=10)
clear_button = tk.Button(root, text="清空", command=clear_listbox)
clear_button.pack(pady=10)

# 创建 Listbox
listbox = tk.Listbox(root)
listbox.pack(pady=10)

# 运行主循环
root.mainloop()
